package com.example.script.portal.service.impl;

import com.example.script.mapper.CommentMapper;
import com.example.script.model.Comment;
import com.example.script.portal.enums.CommentResult;
import com.example.script.portal.model.dto.CreatCommentForm;
import com.example.script.portal.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    int result = 0;

    @Override
    public CommentResult creatComment(CreatCommentForm form) {
        Comment comment = new Comment();
        comment.setScriptId(form.getScriptId());
        comment.setCommentMsg(form.getComment_msg());
        comment.setReplyUserId(form.getReply_user_id());
        comment.setUserId(form.getUserId());
        commentMapper.insert(comment);
        result = commentMapper.insertSelective(comment);
        if (result <= 0) {
            return CommentResult.COMMENT_FILE;
        }
        return CommentResult.COMMENT_SUCCESS;
    }
}
